/**
 * 本地全局字典
 */
import {
    SYS_DIC
} from './sys_dic'
const DIC = {
    ...SYS_DIC,
    STATE: [{
        label: '有效',
        value: 1,
        type: 'success'
    }, {
        label: '无效',
        value: 0,
        type: 'danger'
    }],
    YesNo: [{
        label: '是',
        value: 1,
        type: 'success'
    }, {
        label: '否',
        value: 0,
        type: 'danger'
    }],
    bannerType: [{
        label: '首页顶部',
        value: 1,
        type: 'success'
    }, {
        label: '商品分类广告',
        value: 2,
        type: 'danger'
    }]
}

function getLabelFromDic(dicKey, key) {
    if (typeof dicKey === 'string') {
        dicKey = DIC[dicKey];
    }
    const results = dicKey.filter(el => el.value === key);
    if (results && results.length) {
        return results[0].label;
    }
    return ''
}

function getLabelFromDicV2(dic, fieldName, fieldValue) {
    if (dic && dic[fieldName]) {
        return (dic[fieldName].filter(el => el.value == fieldValue)[0] || {}).label;
    }
    return fieldValue;
}

export {
    getLabelFromDic,
    getLabelFromDicV2,
    DIC
}
